﻿using System;
using System.Runtime.Serialization;
using CWB.Common.Constant;
using CWB.Common.Logging;
using CWB.Common.Utilities;

namespace CWB.Web.Models
{
    [DataContract]
    public class ResultBase
    {
        public ResultBase()
        {
            Result = ReturnCode.Failed;
        }

        public void setException(Exception ex, string ClassName)
        {
            Result = ReturnCode.Failed;
            ISysLog Log = SysLog.GetLogger(ClassName);
            Message = Localization.TranslateMessage(ex.Message, MessageType.Error);
            Log.Exception(ex);
        }

        public void setException(Msg m, string ClassName)
        {
            Result = ReturnCode.Failed;
            ISysLog Log = SysLog.GetLogger(ClassName);
            Message = Localization.TranslateMessage(m);
            Log.Exception(Message);
        }

        public void setException(Err e, string ClassName)
        {
            Result = ReturnCode.Failed;
            ISysLog Log = SysLog.GetLogger(ClassName);
            Message = Localization.TranslateMessage(e);
            Log.Exception(Message);
        }

        
        [DataMember(Name = "msg")]
        public string Message { get; set; }
        private ReturnCode _returncode;

        public ReturnCode Result
        {
            get
            {
                return _returncode;
            }
            set
            {
                _returncode = value;
            }
        }

        [DataMember(Name = "code")]
        public int Code
        {
            private set { }
            get
            {
                return (int)Result;
            }
        }

    }
}
